<template>
	<view class="index">
		<scroll-view class="scroll f-1 bf8 db" scroll-y="true">
			<!--简洁 -->
			<view class="f-1 p10 bff1">
				<view class="box" v-for="(item,i) in orderList" :key="i">
					<view class="prid">
						<view>{{item.name}}</view>
						<!-- <view class="jiao">
							<view class="jiaohang">
								<u-tag class="rijianju" v-if="item.dy_sync_status!=1" :text="sync_statusList[item.dy_sync_status].name"
									:type="sync_statusList[item.dy_sync_status].type" mode="light" plain/>
								<u-tag mode="light" :text="operate_statusList[item.operate_status].name"
									:type="operate_statusList[item.operate_status].type" plain/>
							</view>
						</view> -->
					</view>
					<!-- <view class="prod">
						<view class="prname">{{item.dy_product_id}}</view>
						<view class="price">¥ {{item.price/100}}</view>
					</view> -->
					<!-- 操作 -->
					<view class="f-x-e mt10 pt10 bt1">
						<view class="f-g-0 w30 p-0-10" @click="edit(item)">
							<u-button type="primary" :customStyle="{marginLeft: '20rpx',color:'#000'}" text="编辑"
								color="#ffaa00" :plain="true" shape="circle" size="medium">
							</u-button>
						</view>
						<view class="f-g-0 w30 p-0-10" @click="deleteItem(item)"
							>
							<u-button type="primary" :customStyle="{marginLeft: '20rpx',color:'#000'}" text="删除"
								color="#ffaa00" :plain="true" shape="circle" size="medium">
							</u-button>
						</view>
					</view>
				</view>
				<view class="zhanwei"></view>
			</view>
		</scroll-view>
		<view class="f-g-1 goodw guding">
			<view class="navbar2 bt f-row">
				<view class="f-1 f-row bf">
					<template v-for="(v, i) in navs">
						<view class="f-1 f-y-c" @click="djTab(v)" :key="i">
							<view class="wh f-c f-y-c">
								<text class="cf7c mr10" :style="{ color: subColor ,fontSize:'38rpx'}"
									:class="['icon' + v.i, 'iconfont f20']"></text>
								<view class="">{{ v.t }}</view>
							</view>
						</view>
					</template>
				</view>
			</view>
		</view>
		<u-modal :show="show" :content="content" :showCancelButton="true" @cancel="closeshow" @close="closeshow" @confirm="confirm"></u-modal>
	</view>
</template>

<script>
	export default {
		components: {

		},
		data() {
			return {
				queryForm: {
					pageNo: 1,
					pageSize: 10,
				},
				orderList: [],
				sync_statusList: {
					'0': {
						type: 'info',
						name: '未同步',
					},
					'1': {
						type: 'success',
						name: '已同步',
					},
					'2': {
						type: 'error',
						name: '编辑未同步',
					},
				},
				operate_statusList: {
					'1': {
						type: 'success',
						name: '上架',
					},
					'2': {
						type: 'error',
						name: '下架',
					},
				},
				subColor: uni.getStorageSync('subject_color'),
				navs: [{
					i: '-jiahao',
					k: 'xjsp',
					url: 'xzlx',
					t: '新建加料组'
				}],
				show:false,
				content:'',
				activeObj:{},
			}
		},
		onLoad() {},
		onShow() {
			//获取数据
			this.getDianPrList();
		},
		watch: {

		},
		methods: {
			djTab(v){
				if(v.url=='xzlx'){
					uni.navigateTo({
						url: `/pages/home/diandan/jialiaozu/model/save`
					})
				}
			},
			edit(val) {
				uni.navigateTo({
					url: `/pages/home/diandan/jialiaozu/model/save?id=`+val.id
				})
			},
			deleteItem(val){
				this.activeObj=val;
				this.content='是否删除该加料组吗？';
				this.show=true;
			},
			async confirm(){
				let {
					code,
					msg
				} = await this.beg.request({
					url: '/admin/product.AddFood/classDeleted',
					method: 'POST',
					data: {
						id: this.activeObj.id,
						is_deleted:1
					},
				})
				if(code==1){
					this.fetchData();
					this.activeObj={};
					this.show=false;
				}
				uni.$u.toast(msg)
			},
			closeshow(){
			this.show=false;	
			},
			getDianPrList() {
				this.fetchData();
			},
			async fetchData() {
				this.status = 'loading'
				let {
					data: {
						data,
						count
					},
				} = await this.beg.request({
					url: '/admin/product.AddFood/addClassIndex',
					method: 'POST',
					data: {
						page: this.queryForm.pageNo,
						limit: this.queryForm.pageSize,
						id: '',
						name: '',
						operate_status: '',
						is_deleted: 0
					},
					// data: this.queryForm,
				})
				if (this.queryForm.pageNo == 1) {
					this.orderList = data
				} else {
					if (data.length == 0) {
						this.status = 'nomore'
						return
					}
					this.orderList = this.orderList.concat(data)
				}
				this.status = 'loadmore'
				this.time = ''
			},
		}
	}
</script>

<style lang="scss" scoped>
	.box {
		background-color: #fff;
		padding: 20rpx;
		line-height: 1.5;
		position: relative;
		margin-top: 20rpx;
		border-radius: 20rpx;



		.prid {
			font-weight: bold;
			font-size: 32rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.jiao {
				right: 10rpx;

				.jiaohang {
					display: flex;
					align-items: center;

					.rijianju {
						margin-right: 10rpx;
					}
				}
			}
		}

		.prod {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-top: 20rpx;
		}

		.prname {
			width: 80%;
			overflow: hidden;
			text-overflow: ellipsis;
			display: -webkit-box;
			-webkit-line-clamp: 2;
			-webkit-box-orient: vertical;
		}

		.price {
			width: 20%;
			text-align: right;
		}
	}
	.zhanwei{
		height: 100rpx;
	}
	.guding{
		width: 100%;
		height: 100rpx;
		background-color: #fff;
		position: fixed;
		bottom: 0rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.u-button{
		height: 60rpx;
		width: 100%;
	}
</style>